home *** CD-ROM | disk | FTP | other *** search
- ;; $Id: c_only.pro,v 1.2 1997/01/28 22:40:21 kirk Exp $
- ;;
- ;; NAME:
- ;; c_only.pro
- ;;
- ;; PURPOSE:
- ;; This C function is used to demonstrate how to pass IDL variables
- ;; to a C function via the CALL_EXTERNAL function.
- ;;
- ;; CATEGORY:
- ;; Dynamic Link
- ;;
- ;; CALLING SEQUENCE:
- ;; This function is called in IDL by using the following command
- ;;
- ;; IDL> c_only
- ;;
- ;; INPUTS:
- ;; None.
- ;;
- ;; OUTPUTS:
- ;; None.
- ;;
- ;; SIDE EFFECTS:
- ;; The value of IDL variables are written to standard output
- ;; before and after calls using CALL_EXTERNAL.
- ;;
- ;; RESTRICTIONS:
- ;; This procedure assumes that all of the dynamic libraries are
- ;; present. If they are not they can be built using the provided
- ;; Makefile (run make_callext_demo).
- ;;
- ;;
- ;; MODIFICATION HISTORY:
- ;; Written October, 1993 KDB
- ;;
- ;;===========================================================================
-
- PRO C_ONLY
-
- ;; Different platforms have different filename extensions and entry
- ;; point formats. Determine what type of machine we are on and set the
- ;; correct names.
-
- CASE !VERSION.ARCH OF
-
- 'sparc' :BEGIN ;Sun or Solaris
-
- LIB_EXT = 'so'
- ENTRY_PREFIX = ''
-
- END
-
- 'hp_pa' :BEGIN ;HP
-
- LIB_EXT = 'sl'
- ENTRY_PREFIX = ''
-
- END
-
- 'hp9000s300' :BEGIN ;HP 9000s300 series
-
- LIB_EXT = 'sl'
- ENTRY_PREFIX = '_'
-
- END
-
- 'ibmr2' :BEGIN ;IBM RS6000
-
- LIB_EXT = 'a'
- ENTRY_PREFIX = ''
-
- END
-
- 'mipseb' :BEGIN ;SGI IRIX, or MIPS, or Ultix
-
- ;; Call_External is only supported on IRIX version 5.1.
- ;; Check that this is the operating system in use.
-
- tmp = findfile('/usr/lib/libC.so', COUNT=CNT )
-
- IF((CNT eq 1)and(!VERSION.OS eq "IRIX"))THEN BEGIN
- LIB_EXT = 'so'
- ENTRY_PREFIX = ''
- ENDIF ELSE BEGIN
-
- MESSAGE, /CONTINUE, $
- "Operating System version does not support CALL_EXTERNAL"
- RETURN
-
- ENDELSE
-
- END
-
- 'alpha' :BEGIN ;Dec OSF1
-
- LIB_EXT = 'so'
- ENTRY_PREFIX = ''
- END
-
- 'x86' :BEGIN ;Data General Aviion
-
- LIB_EXT = 'so'
- ENTRY_PREFIX = ''
- END
-
- ELSE :BEGIN
-
- MESSAGE,"CASE ERROR: User must add correct entry name", $
- /CONTINUE
-
- RETURN
-
- END
- ENDCASE
-
- ;; This procedure assumes that we are in the directory that
- ;; contains the dynamic libraries
-
- CD, '.', CURRENT = PWD
-
- ;; Declare the variables that are passed into the C function
- ;; simple
-
- BYTE_VAR = 1B
- SHORT_VAR = 2
- LONG_VAR = 3L
- FLOAT_VAR = 4.0
- DOUBLE_VAR = 5D0
- STRING_VAR = "SiX"
-
- ;; Lets print the parameters that we are going to pass into the
- ;; C function
-
- PRINT,""
- PRINT,"====================================================="
- PRINT,"Inside IDL: Before the call to the C function simple"
- PRINT,""
- PRINT,"Values of variables that will be passed in:"
- PRINT,""
- PRINT," IDL BYTE Variable: ", BYTE_VAR, $
- FORMAT="(A,I4)"
- PRINT," IDL INT Variable: ", SHORT_VAR, $
- FORMAT="(A,I4)"
- PRINT," IDL LONG Variable: ", LONG_VAR, $
- FORMAT="(A,I4)"
- PRINT," IDL FLOAT Variable: ", FLOAT_VAR, $
- FORMAT="(A,F4.1)"
- PRINT," IDL DOUBLE Variable: ", DOUBLE_VAR, $
- FORMAT="(A,F4.1)"
- PRINT," IDL STRING Variable: ", STRING_VAR, $
- FORMAT="(A,A4)"
- PRINT,""
- PRINT,"Calling the C function simple via CALL_EXTERNAL
- PRINT,"====================================================="
-
- PRINT," "
-
- ;; Lets square these values. The string is RETURNED by the function.
-
- STRING_VAR2 = CALL_EXTERNAL(PWD+'/simple.'+LIB_EXT, $
- ENTRY_PREFIX+'simple', $
- BYTE_VAR, SHORT_VAR, LONG_VAR, FLOAT_VAR, $
- DOUBLE_VAR, STRING_VAR, /S_VALUE )
-
- ;; Now print out the results
-
- PRINT,""
- PRINT,"====================================================="
- PRINT,"Inside IDL: Results of C function simple. "
- PRINT," Simple variables are squared in the C function"
- PRINT,""
- PRINT,"Results:"
- PRINT," Squared BYTE Variable: ", BYTE_VAR, $
- FORMAT="(/A,I6)"
- PRINT," Squared INT Variable: ", SHORT_VAR, $
- FORMAT="(A,I6)"
- PRINT," Squared LONG Variable: ", LONG_VAR, $
- FORMAT="(A,I6)"
- PRINT," Squared FLOAT Variable: ", FLOAT_VAR, $
- FORMAT="(A,F6.1)"
- PRINT," Squared DOUBLE Variable: ", DOUBLE_VAR, $
- FORMAT="(A,F6.1)"
- PRINT," Squared STRING Variable: ", STRING_VAR2, $
- FORMAT="(A,A6)"
- PRINT,""
- PRINT,"====================================================="
-
- PRINT," "
-
- ;; Now set up the values that will be passed into the C function
- ;; double_array. This function returns the maximum value in the
- ;; array. Create some data
-
- ARRAY_VAR = abs(randomn(seed,12))*!DPI*10d0 ;create a double array
- ARRAY_SIZE = n_elements(ARRAY_VAR)
-
- MAX = CALL_EXTERNAL(PWD+'/double_array.'+LIB_EXT, $
- ENTRY_PREFIX+'double_array', $
- ARRAY_VAR, ARRAY_SIZE, /D_VALUE)
-
- PRINT," "
- PRINT,"The max value and type returned to IDL from double array:"
- HELP, MAX
-
- PRINT," "
- PRINT,"The max value of the array using the IDL MAX function: ", $
- max(ARRAY_VAR)
-
- ;; Now set up the values that will be passed to the C function
- ;; string_array.
-
- ARRAY_VAR = ['january','february','march', 'april', 'may', 'june', $
- 'july', 'august', 'september','october', 'november', $
- 'december' ]
- ARRAY_SIZE = long(n_elements(ARRAY_VAR))
-
- MAX = CALL_EXTERNAL(PWD+'/string_array.'+LIB_EXT, $
- ENTRY_PREFIX+'string_array', $
- ARRAY_VAR, ARRAY_SIZE, /S_VALUE)
-
- PRINT," "
- PRINT,"The max value and type returned to IDL from string array:"
- HELP, MAX
-
- PRINT," "
- PRINT,"The max value of the array using the IDL MAX function: ", $
- max(ARRAY_VAR)
-
- RETURN
-
- END
-
-